package com.cike.productmanager.DBHelper;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

public class ContractInfoContentHandler  extends DefaultHandler{

	private static final String TAG = "XMLContentHandler";
	private List<ContractInfo> contractInfos;
	private ContractInfo contractInfo;
	private String preTag;
	
	
	public List<ContractInfo> getContractInfos()
	{
		return contractInfos;
	}

	
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		// TODO Auto-generated method stub
		super.characters(ch, start, length);
		String data=null;
		if (contractInfo!=null)
		{
			if("name".equals(preTag))
			{
				data = new String(ch, start,length);
				contractInfo.name=data;
				contractInfo.storeName=data;//�ŵ�������ͬ���һ��ģ�
			}
			else if("id".equals(preTag))
			{
				data = new String(ch, start,length);
				contractInfo.id=data;
			}
			else if("type".equals(preTag))
			{
				data = new String(ch, start,length);
				contractInfo.type=data;
			}
			
			else if("code".equals(preTag))//
			{
				data = new String(ch, start,length);
				contractInfo.storecode=data;
			}
			else if("starttime".equals(preTag))//
			{
				data = new String(ch, start,length);
				contractInfo.startTime=data;
			}
			else if("endtime".equals(preTag))//�ͻ�����
			{
				data = new String(ch, start,length);
				contractInfo.endTime=data;
			}

			else if("content".equals(preTag))
			{
				data = new String(ch, start,length);
				contractInfo.content=data;
			}
			else if("state".equals(preTag))
			{
				data = new String(ch, start,length);
				contractInfo.state=data;
			}
			else if("remark".equals(preTag))
			{
				data = new String(ch, start,length);
				contractInfo.remark=data;
			}
			
			
			
		}
		Log.i(TAG, "�������ݣ�"+new String(ch, start,length));
		
	}

	@Override
	public void endDocument() throws SAXException {
		// TODO Auto-generated method stub
		super.endDocument();
		Log.i(TAG, "�ĵ��������");
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		// TODO Auto-generated method stub
		super.endElement(uri, localName, qName);
		if ("plan".equals(localName)&&contractInfo!=null)
		{
			contractInfos.add(contractInfo);
			contractInfo = null;
		}
		String tag=preTag;
		preTag = null;
		Log.i(TAG, localName + "�������");
		
	}

	@Override
	public void startDocument() throws SAXException {
		// TODO Auto-generated method stub
		super.startDocument();
		contractInfos = new ArrayList<ContractInfo>();
		Log.i(TAG, "��ʼ����...");
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		// TODO Auto-generated method stub
		super.startElement(uri, localName, qName, attributes);

		try {
			if ("plan".equals(localName)) 
			{
				contractInfo = new ContractInfo();
//				report.setReportName(new String(attributes.getValue("reportName")));
			}

			
			preTag = localName;
			Log.i(TAG, "����Ԫ�أ�" + localName);
		} catch (Exception e)
		{
//			Util.Log(e.toString());
		}
	}

	
}
